package galaxies.starRegions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import view.EViewList;

import com.jme3.math.Vector2f;

/*
 * Dimension data used to place stars in a particular core segment.
 */
public class StarRegionSpiralCoreModel {
	
	private Vector2f location = new Vector2f();
	private double rotation = 0.0;
	
	private double area = 0.0;	
	private LinkedHashMap<Integer, Vector2f> corners = new LinkedHashMap<Integer, Vector2f>();
	private ArrayList<Vector2f> points = new ArrayList<Vector2f>();
	
	public StarRegionSpiralCoreModel(LinkedHashMap<Integer, Vector2f> corners) {
		this.corners.putAll(corners);
		calcPoints();
		computeArea();
	}
	
	private void computeArea() {
		float x1 = corners.get(0).x;
		float y1 = corners.get(0).y;
		
		float x2 = corners.get(1).x;
		float y2 = corners.get(1).y;
		
		float x3 = corners.get(2).x;
		float y3 = corners.get(2).y;
		
		float a = (float) Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
		float b = (float) Math.sqrt((x3-x2)*(x3-x2) + (y3-y2)*(y3-y2));
		float c = (float) Math.sqrt((x3-x1)*(x3-x1) + (y3-y1)*(y3-y1));
		
		//Heron's formula
		float s = (a+b+c)*0.5f;
		
		this.area = Math.sqrt(s*(s-a)*(s-b)*(s-c));
	}
	
	public LinkedHashMap<Integer, Vector2f> getCorners() {
		return this.corners;
	}
	
	private void calcPoints() {		
		points.clear();
		
		for (Map.Entry<Integer, Vector2f> entry : corners.entrySet()) {			
			this.points.add(entry.getValue());			
		}				
	}
	
	public ArrayList<Vector2f> getPoints() {
		return this.points;
	}
	
	public void addCorner(Integer index, Vector2f corner) {
		this.corners.put(index, corner);
		calcPoints();
	}
	
	public void setLocation(Vector2f location) {
		this.location = location;
	}
	
	public Vector2f getLocation() {
		return this.location;
	}
	
	public double getRotation() {
		return this.rotation;
	}
	
	public void setRotation(double rotation) {
		this.rotation = rotation;
	}
	
	public double getArea() {
		return this.area;
	}
}
